/***百城联盟***/
package com.yami.shop.platform.task;

import com.xxl.job.core.handler.annotation.XxlJob;
import com.yami.shop.bean.model.PersonNftApply;
import com.yami.shop.common.config.Constant;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.RedisUtil;
import com.yami.shop.personnft.common.service.PersonNftApplyService;
import com.yami.shop.service.PersonnftThanfserRefundService;
import com.yami.shop.service.SysConfigService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * @author yami
 */
@Component
public class PersonnftTask {
    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private PersonNftApplyService personNftApplyService;
    @Autowired
    private SysConfigService sysConfigService;
    @XxlJob("taskCheckAllNftData")
    public void chekSendData(){
        if(!RedisUtil.hasKey("taskCheckAllNftData")){
            logger.info("10分钟 检查并修改资产划转完成*************");
            RedisUtil.set("taskCheckAllNftData","true",10);
//            personNftApplyService.taskCheckAllNftData();
        }
    }
    @XxlJob("chekSendDataNfts")
    public void chekSendDataNfts(){
        if (!RedisUtil.hasKey("chekSendDataNfts")) {
            logger.info("表示周一到周五每天上午9.40,9.50或13.40，13.50执行作业定时执行转移恒生*********************");
            RedisUtil.set("chekSendDataNfts1", "true", 10);
            personNftApplyService.taskChekSendDataNfts();
        }
    }


    @XxlJob("personThanserResultTask")
    public void personThanserResultTask() {
        logger.info("划转定时结果查询*************");
        if(!RedisUtil.hasKey("taskChekSendDataResult")){
            RedisUtil.set("taskChekSendDataResult","true",10);
            personNftApplyService.taskChekSendDataResult();
        }
    }


    @XxlJob("personVerifyNft")
    public void personVerifyNft() {
        if(!RedisUtil.hasKey("personVerifyNft")){
            logger.info("交收定时处理增加持仓*************");
            RedisUtil.set("personVerifyNft","true",10);
            personNftApplyService.taskAddPersonVerifyNft();
        }
    }


    @XxlJob("refundThansferPersonnft")
    public void refundThansferPersonnft() {
        if(!RedisUtil.hasKey("refundThansferPersonnft")){
            logger.info("转增过期处理*************");
            RedisUtil.set("refundThansferPersonnft","true",10);
            personNftApplyService.refundThansferPersonnft();
        }
    }

    @XxlJob("changeCeceiptApplyNft")
    public void changeCeceiptApplyNft() {
        if(!RedisUtil.hasKey("changeCeceiptApplyNft")){
            logger.info("下游资产转移到账检测*************");
            RedisUtil.set("changeCeceiptApplyNft","true",10);
            personNftApplyService.changeCeceiptApplyNft();
        }
    }

    @XxlJob("thansferApplyNft")
    public void thansferApplyNft() {
        Boolean sysConfigObject = sysConfigService.getSysConfigObject(Constant.TRANSFER_SWITCH_CONFIG, Boolean.class);
        if(sysConfigObject){
            if(!RedisUtil.hasKey("thansferApplyNft")){
                logger.info("划转自动审核*************");
                RedisUtil.set("thansferApplyNft","true",10);
                PersonNftApply personNftApply  = new PersonNftApply();
                personNftApply.setSceneType("3");
                personNftApply.setStatus(0);
                personNftApply.setChannelType("1");
                List<PersonNftApply> list = personNftApplyService.listByParam(personNftApply);
                if(list.size()==0){
                    throw new YamiShopBindException("yami.personnft.thansfer.nftFromTo.check");
                }
                for (PersonNftApply nftApply:list) {
                    try {
                        personNftApplyService.changeCeceiptApply(nftApply.getId(),"1",null);
                    }catch (Exception e){
                        logger.info(e.getMessage());
                    }
                }
            }
        }
    }

}
